var stepId = $CertusJsonAjax.getStepInstanceId();
var processId = $CertusJsonAjax.getProInstanceId();
$CertusFormAjax.ajax("findStageInfo",{"processId":processId}, function(result){
    var data = result.data.map;
    $$scope.proNo = data.pro_no;
    $$scope.deptName = data.deptName;
    var proType = data.proType;
    if(proType=="ZL"){
        $$scope.proType="战略类";
    }else if (proType=="YF"){
        $$scope.proType="研发类";
    }else if (proType=="XS"){
        $$scope.proType="销售类";
    }else if (proType=="BM"){
        $$scope.proType="部门类";
    }else if (proType=="SW"){
        $$scope.proType="事务类";
    }else if (proType=="CS"){
        $$scope.proType="测试类";
    }

    if (proType=="XS"){
        $$scope.showSign = true;
        $$scope.showHk = true;
        $$scope.showArea = true;
        $$scope.showCus = true;
        $$scope.showCompare = true;
        $$scope.isPolicy = true;
        $$scope.isCompetitor = true;
        $$scope.proArea = data.pro_area;
        $$scope.cusName = data.cus_name;
        $$scope.divineSignDate = data.divine_sign_date;
        $$scope.divineHkDate = data.divine_hk_date;
    }else if (proType=="ZL"||proType=="SW"
        ||proType=="BM"){
        $$scope.showFinish = true;
        $$scope.divineFinishTime = data.divine_finish_time;
    }else {
        $$scope.showVersion = true;
        $$scope.divineVersionTime = data.divine_version_time
    }

    $$scope.proName = data.pro_name;
    if (data.proLv==3){
        $$scope.clueLv = "高";
    }else if (data.proLv==2){
        $$scope.clueLv = "中";
    }else {
        $$scope.clueLv = "低";
    }

    if (data.is_compare==1){
        $$scope.isCompare = "有";
    }else{
        $$scope.isCompare = "无";
    }

    if (data.jurgency==1){
        $$scope.urgency="紧急";
    }else{
        $$scope.urgency="不紧急";
    }

    if (data.jimportance==0){
        $$scope.importance="一般";
    }else if (data.jimportance==1){
        $$scope.importance="重要";
    }else{
        $$scope.importance="战略";
    }

    $$scope.clueDesc = data.clue_desc;
    $$scope.cusPolicy = data.cus_policy;
    $$scope.competitor = data.competitor;
    $$scope.divineMoney = data.divine_money;
    $$scope.cusBudget = data.cus_budget;
    $$scope.divineContactMoney = data.divine_contact_money;
    $$scope.divineBusinessMoney = data.divine_business_money;
    $$scope.divinePurchaseMoney = data.divine_purchase_money;
    $$scope.moneyDesc = data.money_desc;
    $$scope.clueApplyDesc = data.clue_apply_desc;
    $$scope.proId = data.pro_id;
    $$scope.tid = data.id;
    $$scope.startTime = data.start_time;
    $$scope.endTime = data.end_time;
    $$scope.deptNames = result.data.deptNames;

    var arr = result.data.bugetList;
    var other1Columns = [{
        id: 'bugetPhase',
        title: '阶段',
        type: 'string',
        width: 100,
        columnClass: 'text-center',
    },{
        id: 'bugetType',
        title: '预算类型',
        type: 'string',
        width: 100,
        columnClass: 'text-center',
    }, {
        id: 'buget',
        title: '预算金额',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    },{
        id: 'budgetBegin',
        title: '开始时间',
        type: 'string',
        width: 100,
        columnClass: 'text-center',
        resolution: function (value) {
            var content = '';
            if (value==""){
                return content;
            }else{
                var date = new Date(value);
                content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd");
                return content;
            }

        }
    },{
        id: 'budgetEnd',
        title: '结束时间',
        type: 'string',
        width: 100,
        columnClass: 'text-center',
        resolution: function (value) {
            var content = '';
            if (value==""){
                return content;
            }else{
                var date = new Date(value);
                content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd");
                return content;
            }

        }
    },{
        id: 'comments',
        title: '费用说明',
        type: 'string',
        columnClass: 'text-left'
    }];
    var other1Option = {
        lang: 'zh-cn',
        ajaxLoad: false,
        extraWidth: 20,
        // loadURL:'url',
        exportFileName: '其他费用',
        datas: arr,
        columns: other1Columns,
        gridContainer: 'other1Container',
        tools: ''
    };
    var other1Grid = $.fn.dlshouwen.grid.init(other1Option);
    other1Grid.load();

    //人天预估
    var rlColumns = [{
        id: 'roleName',
        title: '角色',
        type: 'string',
        columnClass: 'text-center'
    },{
        id: 'level',
        title: '级别',
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '';
            if (value=="1"){
                content = "低";
            }else if (value=="2"){
                content = "中";
            }else{
                content = "高";
            }
            return content;
        }
    },{
        id: 'beginTime',
        title: '开始时间',
        type: 'date',
        format: 'yyyy-MM-dd',
        otype: 'time_stamp_ms',
        columnClass: 'text-center',
    }, {
        id: 'endTime',
        title: '结束时间',
        type: 'date',
        format: 'yyyy-MM-dd',
        otype: 'time_stamp_ms',
        columnClass: 'text-center',
    },{
        id: 'rtNum',
        title: '人天',
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'comments',
        title: '说明',
        type: 'string',
        columnClass: 'text-center',
    }];
    var rlOption = {
        lang: 'zh-cn',
        ajaxLoad: false,
        extraWidth: 20,
        // loadURL:'url',
        exportFileName: '人力成本列表',
        datas: result.data.rtList,
        columns: rlColumns,
        gridContainer: 'rtContainer',
    };
    var rlGrid = $.fn.dlshouwen.grid.init(rlOption);
    rlGrid.load();

    //涉及文件
    var wjColumns = [{
        id: 'productName',
        title: '文件名称',
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'comments',
        title: '说明',
        type: 'string',
        columnClass: 'text-center',
    }];
    var wjOption = {
        lang: 'zh-cn',
        ajaxLoad: false,
        extraWidth: 20,
        // loadURL:'url',
        exportFileName: '人力成本列表',
        datas: result.data.wjList,
        columns: wjColumns,
        gridContainer: 'wjContainer'
    };
    var wjGrid = $.fn.dlshouwen.grid.init(wjOption);
    wjGrid.load();
});

function agreesq(isAgree) {
    if (!certusValidateNotnull()){
        return;
    }
    var spDesc = $("#spDesc").val();
    var proId = $("#proId").val();
    var tid = $("#tid").val();
    $CertusFormAjax.ajax("agreeClueSq",{"spDesc":spDesc,"proId":proId,"tid":tid,"stepId":stepId,"isAgree":isAgree}, function(result){
        layer.msg("审批成功");
        window.history.back();
    });
}

function toTh() {
    var spDesc = $("#spDesc").val();
    var proId = $("#proId").val();
    var tid = $("#tid").val();
    $CertusFormAjax.ajax("thClueSq",{"spDesc":spDesc,"proId":proId,"tid":tid,"stepId":stepId,"processId":processId}, function(result){
        layer.msg("退回成功");
        window.history.back();
    });
}